<template>
	<view>
		<nav-bar leftIcon="left"></nav-bar>
		<view class="text">
			{{ $t('銷燬流量包:1GB=0.1CFP的價格回收,回收后的CFP將轉入到餘額。') }}
			<view @click="submit" class="btn-sub">
				{{ $t('確認回收') }}
			</view>
		</view>

		<uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog ref="inputClose" mode="input" :title="$t('輸入您的交易密碼')" :placeholder="$t('請輸入')"
				@confirm="dialogInputConfirm" :value="valueText" :cancelText="$t('取消')"
				:confirmText="$t('確認')"></uni-popup-dialog>
		</uni-popup>
	<uni-popup ref="inputDialog" type="dialog" v-if="!typePass">
		<uni-popup-dialog ref="inputClose" mode="input" :title="$t('輸入您的交易密碼')" :placeholder="$t('請輸入')"
		  @confirm="dialogInputConfirm" :value="valueText" :cancelText="$t('取消')"
		  :confirmText="$t('確認')"></uni-popup-dialog>
	  </uni-popup>
	  <uni-popup ref="inputDialog" type="dialog" v-if="typePass"> 
		<uni-popup-dialog ref="inputClose" mode="input" :title="$t('輸入您的谷歌密鑰')" :placeholder="$t('請輸入')"
		  @confirm="dialogInputConfirm" :value="valueText" :cancelText="$t('取消')"
		  :confirmText="$t('確認')"></uni-popup-dialog>
	  </uni-popup>		
	</view>
</template>

<script setup>
import { ref } from 'vue'
import { axios } from '@/service/request.js'
import i18n from '@/locale/index'

const inputDialog = ref()
const valueText = ref('') //交易密码
const typePass = ref(false)
let getStorage = async() =>{
    //这是一个异步接口
    await uni.getStorage({
      key:'googleVerificationSwitch',//本地缓存中的指定的 key
      success(res) {//接口调用的回调函数，res = {data: key对应的内容}
        typePass.value = res.data
      }
    })
  }
function submit() {
	getStorage()
	inputDialog.value.open()
}

async function dialogInputConfirm(val) {
	valueText.value = val
	await axios('record/userRecordExit', {
		userId: uni.getStorageSync('setUserInfo').userId,
		payPassword: valueText.value
	})
	uni.showToast({
		title: `${i18n.global.t('回收成功')}!`,
	})
	uni.navigateBack({
		delta: 1
	});
}
</script>

<style>
.text {
	padding: 30rpx;
	color: #fff;
}

.btn-sub {
	width: 690rpx;
	height: 90rpx;
	margin-top: 950rpx;
	background: linear-gradient(90deg, #039BDA, #0DF2ED);
	border-radius: 45rpx;
	text-align: center;
	line-height: 90rpx;
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #FFFFFF;
}
</style>